package com.wwwarehouse.carddesk.utils;

import android.content.Intent;
import android.os.Bundle;

import com.wwwarehouse.carddesk.constant.CardDeskConstant;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.bean.ConvertToPcParams;
import com.wwwarehouse.common.bean.response.CardDeskFunctionResponseBean;
import com.wwwarehouse.common.bean.response.CardDeskTaskResponseBean;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.common.fragment.PcImportUnifyFragment;

import java.util.HashMap;
import java.util.Map;

import static com.wwwarehouse.common.activity.base.BaseApplication.sp;

/**
 * Created by Jackie on 2017/10/24.
 * 任务桌面跳转路径
 */

public class TaskRouterUtils {

    private static final String KEY_TYPE = "type";
    public static final String ACTION_IMPORT_RESOURCE = "import_resource";

    /**
     * 卡片桌面  任务跳转
     * @param taskType   任务类型
     * @param bundle     参数
     */
    public static void goTask(BaseCardDeskActivity activity, String taskType, Bundle bundle) {
        if ("IMPORT_ITEM".equals(taskType) ||                           //导入物
                "IMPORT_RESOURCE".equals(taskType) ||                   //导入资源
                "IMPORT_RS_STORE".equals(taskType) ||                   //导入仓储资源
                "IMPORT_TOOL".equals(taskType) ||                       //导入工具
                "IMPORT_GOODS".equals(taskType) ||                      //导入商品
                "IMPORT_RS_SALE".equals(taskType) ||                    //导入供货资源
                "IMPORT_RS_LABOUR".equals(taskType) ||                  //导入劳务资源
                "IMPORT_RS_TRANSPORT".equals(taskType)) {               //导入运输资源

            Intent intent = new Intent(ACTION_IMPORT_RESOURCE);
            intent.putExtras(bundle);
            activity.sendOrderedBroadcast(intent, null);
        } else if ("CREATE_H_GOODS".equals(taskType)) {                 //创建商品
            activity.pushFragment(CardDeskConstant.PATH_CREATE_GOODS, bundle);
        } else if ("CREATE_H_TOOLS".equals(taskType)) {                 //创建工具
            activity.pushFragment(CardDeskConstant.PATH_CREATE_TOOLS, bundle);
        } else if ("CREATE_H_SHOP".equals(taskType)) {                  //创建店铺
            activity.pushFragment(CardDeskConstant.PATH_CREATE_STORE, bundle);
        } else if ("CREATE_H_STOCK".equals(taskType)) {                 //创建仓库
            activity.pushFragment(CardDeskConstant.PATH_CREATE_WAREHOUSE, bundle);
        } else if ("CREATE_H_SALE".equals(taskType) ||                  //创建供货资源
                "CREATE_H_STORE".equals(taskType) ||                    //创建仓储资源
                "CREATE_H_LABOUR".equals(taskType) ||                   //创建劳务资源
                "CREATE_H_PROCESS".equals(taskType) ||                  //创建加工资源
                "CREATE_H_SELL".equals(taskType) ||                     //创建销售资源
                "CREATE_H_TRANSPORT".equals(taskType)) {                //创建运输资源
            activity.pushFragment(CardDeskConstant.PATH_CREATE_RES, bundle);
        } else if ("ACCEPT_INVITE".equals(taskType)) {                  //同意接受邀请
            activity.pushFragment(CardDeskConstant.PATH_AGREE_ACCEPT_INVITE, bundle);
        } else if ("SIGNUP_REVIEW".equals(taskType)) {                  //注册审核
            activity.pushFragment(CardDeskConstant.PATH_REVIEW_INVITEE, bundle);
        } else if ("MODIFY_SIGNUP".equals(taskType)) {                  //修改注册信息
            activity.pushFragment(CardDeskConstant.PATH_MODIFY_REGISTER_INFO, bundle);
        } else if ("CREATE_BUSINESS_MANAGER".equals(taskType)) {        //创建三角链
            activity.pushFragment(CardDeskConstant.PATH_TC_CREATE, bundle);
        } else if ("ACCEPT_INVITE".equals(taskType)) {                  //接受邀请
            activity.pushFragment(CardDeskConstant.PATH_AGREE_2_ACCEPT_INVITE_FRAGMENT, bundle);
        } else if ("CREATE_BUSINESS_PLANNING".equals(taskType)) {       //业务规划
            activity.pushFragment(CardDeskConstant.PATH_TASK_PIN_CARD_MAIN, bundle);
        } else if ("TRADE_IMPORT_SETTING".equals(taskType)) {           //订单导入设置
            bundle.putInt(KEY_TYPE, 2);
            activity.pushFragment(CardDeskConstant.PATH_TASK_IMPORT_ORDERS_PAGER, bundle);
        } else if("INIT_STOCK".equals(taskType)) {                      //初始化库存
            CardDeskTaskResponseBean.TaskBean taskDetailsBean = (CardDeskTaskResponseBean.TaskBean) bundle.getSerializable(Constant.KEY_CARD_DESK_TASK_DETAILS);

            ConvertToPcParams pcParams = new ConvertToPcParams();
            pcParams.setTitle(taskDetailsBean.getCardName() + "");
            pcParams.setUrl(CardDeskConstant.URL_GOTO_INIT_STOCK_INDEX);
            pcParams.setImportSuccessArouterPath(CardDeskConstant.PATH_IMPORT_REAL_THING_SUCCESS);
            Map<String, Object> map = new HashMap<>();
            map.put("businessUnitId", taskDetailsBean.getBelongBusiness());
            map.put("operationUkid", taskDetailsBean.getCardUkid());
            map.put("userId", sp.getValue(Constant.sp_User_Id, ""));
            pcParams.setMap(map);
            bundle.putSerializable(Constant.KEY_CONVERT_TO_PC, pcParams);
            activity.pushFragment(CardDeskConstant.PATH_CONVERT_TO_PC_EMPTY, bundle);
        } else if ("BUSINESS_PARTNER_INVITE".equals(taskType)) {        //业务伙伴邀请
            activity.pushFragment(CardDeskConstant.PATH_INVITE_FRIENDS, bundle);
        } else if ("CREATE_STORAGE_CODE".equals(taskType)) {            //创建库位码
            activity.pushFragment(CardDeskConstant.PATH_TASK_CREATE_STORAGE_CODE, bundle);
        } else if ("CREATE_LOCATION_CODE".equals(taskType)) {           //创建位置码
            activity.pushFragment(CardDeskConstant.PATH_TASK_CREATE_LOCATION_CODE, bundle);
        } else if ("CREATE_IMPORT_CODE".equals(taskType) ||             //导入库位码
                "IMPORT_STOCK_MAP".equals(taskType) ||                  //导入仓库地图
                "IMPORT_TOOLS_BARCODE".equals(taskType)) {              //导入工具条码
            PcImportUnifyFragment pcImportUnifyFragment = new PcImportUnifyFragment();
            pcImportUnifyFragment.setArguments(bundle);
            activity.pushFragment(pcImportUnifyFragment);
        } else if ("CREATE_STOCK_MAP".equals(taskType)) {               //创建仓库地图
            activity.pushFragment(CardDeskConstant.PATH_CREATE_STOCK_MAP, bundle);
        } else if ("PUBLISH_RESOURCE".equals(taskType)) {               //发布资源
            bundle.putString(KEY_TYPE, "task_release");
            activity.pushFragment(CardDeskConstant.PATH_TASK_RELEASE_SUPPLY, bundle);
        } else if ("CREATE_JOB_POINT".equals(taskType)) {               //创建作业点(需要查询步骤)
            activity.pushFragment(CardDeskConstant.PATH_TASK_CREATE_JOB_POINT, bundle);
        } else if ("DELIVER_MANAGE".equals(taskType)) {                 //上传发货信息
            PcImportUnifyFragment pcImportUnifyFragment = new PcImportUnifyFragment();
            pcImportUnifyFragment.setArguments(bundle);
            activity.pushFragment(pcImportUnifyFragment);
        } else if ("MAINTAIN_GOODS_IMAGER".equals(taskType)) {          //维护商品图片
            activity.pushFragment(CardDeskConstant.PATH_MAINTAIN_GOODS_IMAGE, bundle);
        } else if ("START_TO_WORK".equals(taskType)) {                  //去作业
            activity.pushFragment(CardDeskConstant.PATH_TASK_START_TO_WORK, bundle);
        } else if ("BINGDING_STORAGE_CODE".equals(taskType)) {          //绑定库位码
            activity.pushFragment(CardDeskConstant.PATH_SCAN_LOCATION_CODE, bundle);
        }
    }

    /**
     * 卡片桌面  功能跳转
     * @param taskType   功能类型
     * @param bundle     参数
     */
    public static void goFunction(BaseCardDeskActivity activity, String taskType, Bundle bundle) {
        if ("CREATE_RESOURCES".equals(taskType)) {                                  //创建资源
            activity.pushFragment(CardDeskConstant.PATH_CREATE_RES, bundle);
        } else if ("CREATE_H_GOODS".equals(taskType)) {                             //创建商品
            activity.pushFragment(CardDeskConstant.PATH_CREATE_GOODS, bundle);
        } else if ("CREATE_H_TOOLS".equals(taskType)) {                             //创建工具
            activity.pushFragment(CardDeskConstant.PATH_CREATE_TOOLS, bundle);
        } else if ("CREATE_H_SHOP".equals(taskType)) {                              //创建店铺
            activity.pushFragment(CardDeskConstant.PATH_CREATE_STORE, bundle);
        } else if ("CREATE_H_STOCK".equals(taskType)) {                             //创建仓库
            activity.pushFragment(CardDeskConstant.PATH_CREATE_WAREHOUSE, bundle);
        } else if ("UPDATE_RESOURCES".equals(taskType) ||                           //修改资源
                "DELETE_RESOURCES".equals(taskType) ||                              //删除资源
                "UPDATE_H_GOODS".equals(taskType) ||                                //修改商品
                "UPDATE_H_TOOLS".equals(taskType) ||                                //修改工具
                "UPDATE_H_SHOP".equals(taskType) ||                                 //修改店铺
                "UPDATE_H_STOCK".equals(taskType) ||                                //修改仓库
                "DELETE_H_GOODS".equals(taskType) ||                                //删除商品
                "DELETE_H_TOOLS".equals(taskType) ||                                //删除工具
                "DELETE_H_SHOP".equals(taskType) ||                                 //删除店铺
                "DELETE_H_STOCK".equals(taskType)) {                                //删除仓库
            activity.pushFragment(CardDeskConstant.PATH_MODIFY_RES, bundle);
        } else if ("CREATE_BUSINESS_MANAGER".equals(taskType)) {                    //管理三角链
            activity.pushFragment(CardDeskConstant.PATH_TC_AUTHENTICATION, bundle);
        } /* else if ("PUBLISH_RESOURCE".equals(taskType)) {                        //发布资源
            activity.pushFragment(CardDeskConstant.PATH_SELECT_RESOURCE, bundle);
        } else if ("PUBLISH_RESOURCE_VIEW".equals(taskType)) {                      //查看资源
            activity.pushFragment(CardDeskConstant.PATH＿SEE_RESOURCE, bundle);
        } */ else if ("INVITE_USER".equals(taskType)) {                             //邀请用户
            activity.pushFragment(CardDeskConstant.PATH_INVITE_REGISTER, bundle);
        } else if ("CREATE_BUSINESS_UNIT".equals(taskType)) {                       //创建顶级业务单位
            activity.pushFragment(CardDeskConstant.PATH_CREATE_BUSINESS_UNIT, bundle);
        } else if ("AUTH_ITEM".equals(taskType)) {                                  //权限分配
            activity.pushFragment(CardDeskConstant.PATH_AUTHORITY_DISTRIBUTE_PAGER, bundle);
        } else if ("AUTH_RETRIEVE".equals(taskType)) {                              //权限回收
            activity.pushFragment(CardDeskConstant.PATH_AUTHORITY_PR, bundle);
        } else if ("CREATE_BUSINESS_PLANNING".equals(taskType)) {                   //业务规划
            activity.pushFragment(CardDeskConstant.PATH_FUNCTION_PIN_CARD_MAIN, bundle);
        } else if ("TRADE_IMPORT_SETTING".equals(taskType)) {                       //订单导入设置
            bundle.putInt(KEY_TYPE, 2);
            activity.pushFragment(CardDeskConstant.PATH_FUNCTION_IMPORT_ORDERS_PAGER, bundle);
        } else if ("CREATE_UNIT".equals(taskType)) {                                //新增单位
            activity.pushFragment(CardDeskConstant.PATH_NEW_UNIT, bundle);
        } else if ("MODIFY_UNIT".equals(taskType)) {                                //修改单位
            activity.pushFragment(CardDeskConstant.PATH_MODIFY_UNIT, bundle);
        } else if ("ADD_BUSINESS_PARTNER".equals(taskType)) {                       //添加业务伙伴
            activity.pushFragment(CardDeskConstant.PATH_ADD_FRIENDS, bundle);
        } else if ("MAINTAIN_CUSTOMER_PROFILE".equals(taskType)) {                  //维护客户档案
            activity.pushFragment(CardDeskConstant.PATH_CUSTOMER_FILE, bundle);
        } else if ("MAINTAIN_SUPPLIER_PROFILE".equals(taskType)) {                  //维护供应商档案
            activity.pushFragment(CardDeskConstant.PATH_SUPPLIER_FILE, bundle);
        } else if ("PUBLISH_RESOURCE_VIEW".equals(taskType)) {                      //下单(订购商品)
            activity.pushFragment(CardDeskConstant.PATH_PUBLISH_RESOURCE, bundle);
        } else if ("INVENTORY_DEFINITION".equals(taskType)) {                       //定义实物库存
            activity.pushFragment(CardDeskConstant.PATH_INVENTORY_DEFINITION, bundle);
        } else if ("CREATE_STORAGE_CODE".equals(taskType)) {                        //创建库位码
            activity.pushFragment(CardDeskConstant.PATH_FUNCTION_CREATE_STORAGE_CODE, bundle);
        } else if ("CREATE_LOCATION_CODE".equals(taskType)) {                       //创建位置码
            activity.pushFragment(CardDeskConstant.PATH_FUNCTION_CREATE_LOCATION_CODE, bundle);
        } else if ("AdjustContract".equals(taskType)) {                             //调整契约
            activity.pushFragment(CardDeskConstant.PATH_ADJUST_CONTRACT, bundle);
        } else if ("UPDATE_STOCK_MAP".equals(taskType)) {                           //更新仓库地图
            activity.pushFragment(CardDeskConstant.PATH_UPDATE_STOCK_MAP, bundle);
        } else if ("PUBLISH_RESOURCE".equals(taskType)) {                           //发布资源
            bundle.putString(KEY_TYPE, "function_release");
            activity.pushFragment(CardDeskConstant.PATH_FUNCTION_RELEASE_SUPPLY, bundle);
        } else if ("PUBLISH_RESOURCE_MODIFY".equals(taskType)) {                    //修改资源
            bundle.putString(KEY_TYPE, "function_edit");
            activity.pushFragment(CardDeskConstant.PATH_FUNCTION_RELEASE_MODIFY, bundle);
        } else if ("CREATE_JOB_POINT".equals(taskType)) {                           //创建作业点(每次都新建)
            activity.pushFragment(CardDeskConstant.PATH_FUNCTION_CREATE_JOB_POINT, bundle);
        } else if ("ADD_ASSIGN_TASK_RULE".equals(taskType)) {                       // 新增任务分配规则
            activity.pushFragment(CardDeskConstant.PATH_SET_RULES, bundle);
        } else if ("MODIFY_ASSIGN_TASK_RULE".equals(taskType)) {                    // 编辑任务分配规则
            activity.pushFragment(CardDeskConstant.PATH_EDIT_RULES, bundle);
        } else if ("DELIVER_MANAGE".equals(taskType)) {                             //上传发货信息
            CardDeskFunctionResponseBean.TaskBean functionTaskBean = (CardDeskFunctionResponseBean.TaskBean) bundle.getSerializable(Constant.KEY_CARD_DESK_FUNCTION_DETAILS);
            CardDeskTaskResponseBean.TaskBean taskTaskBean = new CardDeskTaskResponseBean.TaskBean();

            taskTaskBean.setCardName(functionTaskBean.getTaskName());
            taskTaskBean.setBelongBusiness(functionTaskBean.getBusinessId());
            taskTaskBean.setTaskType(functionTaskBean.getTaskType());

            Bundle params = new Bundle();
            params.putSerializable(Constant.KEY_CARD_DESK_TASK_DETAILS, taskTaskBean);

            PcImportUnifyFragment pcImportUnifyFragment = new PcImportUnifyFragment();
            pcImportUnifyFragment.setArguments(params);
            activity.pushFragment(pcImportUnifyFragment);
        } else if ("BIND_BANK_CARD".equals(taskType)) {                             //添加企业银行卡
            activity.pushFragment(CardDeskConstant.PATH_BIND_BANK_CARD, bundle);
        } else if ("UNBIND_BANK_CARD".equals(taskType)) {                           //解绑企业银行卡
            activity.pushFragment(CardDeskConstant.PATH_UNBIND_BANK_CARD, bundle);
        } else if ("PAUSE_LOGIN".equals(taskType)) {                                //暂停登录
            activity.pushFragment(CardDeskConstant.PATH_GROUP_STOPLOGIN, bundle);
        } else if ("PAYMENT".equals(taskType)) {                                    //支付
            activity.pushFragment(CardDeskConstant.PATH_PAYMENT, bundle);
        } else if ("START_TO_WORK".equals(taskType)) {                              //去作业
            activity.pushFragment(CardDeskConstant.PATH_FUNCTION_START_TO_WORK, bundle);
        } else if ("ENTER_PROD_TOOLS".equals(taskType)) {                           //录入生成工具
            activity.pushFragment(CardDeskConstant.PATH_INPUT_GENERATION_TOOL, bundle);
        } else if ("BINGDING_STORAGE_CODE".equals(taskType)) {                      //绑定库位码
            activity.pushFragment(CardDeskConstant.PATH_BINDING_STORAGE_CODE, bundle);
        }
    }
}
